/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.utils.StringUtils;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementLoadBo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementLoadVo;
import com.comac.ins.isfd.service.IIsfdModelManagementLoadService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 模型管理-载荷controller
 *
 * @author Lion Li
 * @date 2024-08-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/modelManagementLoad")
public class IsfdModelManagementLoadController extends BaseController {

    private final IIsfdModelManagementLoadService isfdModelManagementLoadService;

    /**
     * 查询模型管理载荷列表
     */
    @SaCheckPermission("isfd:modelManagementLoad:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdModelManagementLoadVo> list(@RequestBody IsfdModelManagementLoadBo bo) {
        return isfdModelManagementLoadService.queryPageList(bo);
    }


    /**
     * 获取模型管理载荷详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:modelManagementLoad:query")
    @GetMapping("/{id}")
    public R<IsfdModelManagementLoadVo> getInfo(@NotNull(message = "主键不能为空")
                                                @PathVariable Long id) {
        return R.ok(isfdModelManagementLoadService.queryById(id));
    }

    /**
     * 新增模型管理载荷
     */
    @SaCheckPermission("isfd:modelManagementLoad:add")
    @Log(title = "模型管理载荷", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public R<Void> add(@RequestParam("file") MultipartFile file,
                       @RequestParam("modelNumber") String modelNumber,
                       @RequestParam("remarks") String remarks) {
        IsfdModelManagementLoadBo isfdModelManagementLoadBo = new IsfdModelManagementLoadBo();
        isfdModelManagementLoadBo.setModelNumber(modelNumber);
        isfdModelManagementLoadBo.setRemarks(remarks);
        return toAjax(isfdModelManagementLoadService.insertByBo(isfdModelManagementLoadBo, file));
    }

//    /**
//     * 修改模型管理载荷
//     */
//    @SaCheckPermission("isfd:modelManagementLoad:edit")
//    @Log(title = "模型管理载荷", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdModelManagementLoadBo bo) {
//        return toAjax(isfdModelManagementLoadService.updateByBo(bo));
//    }

    /**
     * 删除模型管理载荷
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:modelManagementLoad:remove")
    @Log(title = "模型管理载荷", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public R<Void> delete(@RequestBody Long[] ids) {
        return toAjax(isfdModelManagementLoadService.deleteWithValidByIds(List.of(ids)));
    }

    /**
     * 删除预先查询
     */
    @SaCheckPermission("isfd:modelManagementLoad:pre:delete")
    @PostMapping("/pre/delete")
    public R<Boolean> preDelete(@RequestBody Long[] ids) {
        String resultStr = isfdModelManagementLoadService.preDelete(List.of(ids));
        if (StringUtils.isNotBlank(resultStr)) {
            return R.setResult(R.SUCCESS, Boolean.FALSE, resultStr);
        }
        return R.setResult(R.SUCCESS, Boolean.TRUE, null);
    }
}
